package com.substation.ui.fragment;

import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;

import com.bean.LoginInfo;
import com.substation.R;
import com.substation.ui.activity.LoginActivity;
import com.substation.ui.utils.XUtils;
import com.substation.utils.SPUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/5/15.
 */

public class MyFragment extends BaseFragment {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.company)
    TextView company;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.spinner1)
    Spinner spinner;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    protected void initView() {
        LoginInfo loginInfo = LoginInfo.getInfo(context);
        name.setText(loginInfo.getAccountProfileDetails().getNickname());
        company.setText(loginInfo.getProviderUserInfo() == null ? "" : loginInfo.getProviderUserInfo().getProvideName());
        phone.setText(loginInfo.getProviderUserInfo() == null ? "" : loginInfo.getProviderUserInfo().getPhoneNumber() + "");
        toolbar.setTitle("我的");
        int netCount = (int) SPUtils.get(context, "netCount", 0);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                SPUtils.put(context, "netCount", i);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
        spinner.setSelection(netCount);
    }

    @OnClick({R.id.count, R.id.clear, R.id.loginOut})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.count:
                break;
            case R.id.clear:
                XUtils.clear();
                SPUtils.remove(context, "task");
                showMsg("已清除本地缓存");
                break;
            case R.id.loginOut:
                LoginInfo.remove(context);
                startActivity(new Intent(context, LoginActivity.class));
                getActivity().finish();
                break;
        }
    }
}
